#!/bin/bash

# 脚本所在路径：/usr/local/snowfield/script/nginx_restart.sh
# 重启或重载nginx服务
# 当设备的管理口IP地址有变更时，需要将新的IP地址绑定到nginx服务中，并重启或重载
# 1.重启或重载nginx,如果nginx进程未启动，则启动；如果已启动，则重载

# return 0:正常退出，1:启动nginx异常，2:重载nginx异常
#

nginxPidCnt=$(ps ax | grep "/usr/local/nginx/sbin/nginx" | grep -v grep | wc -l)
if [ nginxPidCnt == 0 ];then
  /usr/local/nginx/sbin/nginx
  if [ $? -ne 0 ]; then
      echo "start nginx service error, please check."
      exit 1
  fi
else
  /usr/local/nginx/sbin/nginx -s reload
  if [ $? -ne 0 ]; then
      echo "reload nginx service error, please check."
      exit 2
  fi
fi
exit 0
